Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert C-style stat arrays for game objects to std::vector #3616

Merged
merged 14 commits into from
Feb 1, 2024

Conversation

ManManson
Copy link
Member

This patchset aims to refactor stat vectors by replacing C-style raw pointer arrays by std::vector<SMTH_STATS>. The main benefit is that this prevents the use of pointer arithmetic tricks to access array elements (which was quite common before the change).

Also, many places have used an exploded version of getting the stats by directly accessing the stats arrays, although there was already a bunch of functions designed specifically to avoid doing this in droid.h (get*Stats() function family for DROID). These places were patched to use getStats() functions, instead.

There are still some places that do pointer arithmetic tricks (e.g., to get the component index back from the stat pointer), these will be fixed a bit later.

NOTE: visibility.h header include was removed from droid.h to avoid cyclic dependency between header files, although we use objSensorRange function from it. So, it's declared as extern in droid.h. This is a dirty workaround and will also be fixed later.

There were many places across the WZ code base,
which happened to calculate various object stats
by accessing the global stats arrays directly,
although, there are some utility functions (at least,
for `DROID` class) to get these conveniently.

Replace such occurrences by these getter functions
for `DROID` instances.

Signed-off-by: Pavel Solodovnikov <[email protected]>
The `%zu` format specifier should be nowadays supported
by both MSVC and GCC/Clang, so use this instead of
casting to unsigned int.

Signed-off-by: Pavel Solodovnikov <[email protected]>
There were some places where these functions
were called several times in a row, this can
be easily optimized by saving the result to
a variable.

Signed-off-by: Pavel Solodovnikov <[email protected]>
The old `STATS_DEALLOC` and `ALLOC_STATS` macros
are not needed anymore. Rename `ALLOC_STATS_VECTOR`
to just `ALLOC_STATS`.

Signed-off-by: Pavel Solodovnikov <[email protected]>
@past-due past-due added this to the 4.5.0-beta1 milestone Jan 28, 2024
@KJeff01
Copy link
Member

KJeff01 commented Jan 28, 2024

Could change some of the for loops to use size_t in the init expression. This is rather inconsistent throughout the whole codebase so it's not a big issue. Unless I missed something this looks good to me. 👍

@KJeff01 KJeff01 merged commit 11cce43 into Warzone2100:master Feb 1, 2024
35 checks passed
@ManManson ManManson deleted the stats_refactor branch March 16, 2024 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants